package com.jasperframework.boot.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
  * <p> 统一的参数校验 </p>
  *
  * @site https://miliqkdoc.motopa.cn/
  * @author daizhao
  * @date 2022/12/12 12:12
  */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ParamCheckResult {

    /**
     * 校验结果
     */
    @Builder.Default
    private Boolean pass = true;

    /**
     * 校验结果
     */
    private String msg;
    /**
     * 自定义状态码
     */
    @Builder.Default
    private Integer code = 200;

    public static ParamCheckResult pass() {
        return ParamCheckResult.builder().pass(true).msg("校验通过").build();
    }

    public static ParamCheckResult pass(String msg) {
        return ParamCheckResult.builder().pass(true).msg(msg).build();
    }

    public static ParamCheckResult failed(String msg) {
        return ParamCheckResult.builder().pass(false).code(401).msg(msg).build();
    }

    public static ParamCheckResult failed(Integer code, String msg) {
        return ParamCheckResult.builder().pass(false).code(code).msg(msg).build();
    }


}
